<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:s="http://criticalsystems.co.uk/schemas/instrumentation/02/2009">
  <xsl:output method="text"/>
  <xsl:template match="/">
    <xsl:call-template name="Categories"/>
  </xsl:template>

  <xsl:template name="Categories">
; // ********************************************************
; // - Event categories -
; // Categories must be numbered consecutively starting at 1.
; // ********************************************************

    <xsl:apply-templates mode="Category" select="s:systemInformation/s:subsystems/s:subsystem"/>
    <xsl:call-template name="EventIds"/>
  </xsl:template>
  
  <xsl:template match="s:subsystem" mode="Category">
MessageId=<xsl:value-of select="@categoryId"/>
Severity=Success
SymbolicName=Category_<xsl:value-of select="@categoryId"/>
Language=English
<xsl:value-of select="@name"/>
.

  </xsl:template>
  
  <xsl:template name="EventIds">
; // ********************************************************
; // - Event IDs -
; // ********************************************************

    <xsl:call-template name="BoundaryEventIds">
      <xsl:with-param name="eventIdStart">100</xsl:with-param>
      <xsl:with-param name="symbolPrefix">Subsystem</xsl:with-param>
      <xsl:with-param name="level">Subsystem</xsl:with-param>
    </xsl:call-template>
    <xsl:call-template name="BoundaryEventIds">
      <xsl:with-param name="eventIdStart">200</xsl:with-param>
      <xsl:with-param name="symbolPrefix">Thread</xsl:with-param>
      <xsl:with-param name="level">Thread</xsl:with-param>
    </xsl:call-template>
    <xsl:call-template name="BoundaryEventIds">
      <xsl:with-param name="eventIdStart">300</xsl:with-param>
      <xsl:with-param name="symbolPrefix">Module</xsl:with-param>
      <xsl:with-param name="level">Module</xsl:with-param>
    </xsl:call-template>
    <xsl:call-template name="BoundaryEventIds">
      <xsl:with-param name="eventIdStart">400</xsl:with-param>
      <xsl:with-param name="symbolPrefix">ExternalModule</xsl:with-param>
      <xsl:with-param name="level">External module</xsl:with-param>
    </xsl:call-template>
    <xsl:call-template name="BoundaryEventIds">
      <xsl:with-param name="eventIdStart">500</xsl:with-param>
      <xsl:with-param name="symbolPrefix">Component</xsl:with-param>
      <xsl:with-param name="level">Component</xsl:with-param>
    </xsl:call-template>
    <xsl:call-template name="BoundaryEventIds">
      <xsl:with-param name="eventIdStart">600</xsl:with-param>
      <xsl:with-param name="symbolPrefix">Function</xsl:with-param>
      <xsl:with-param name="level">Function</xsl:with-param>
    </xsl:call-template>
    <xsl:call-template name="OtherEventIds"/>
  </xsl:template>

  <xsl:template name="BoundaryEventIds">
    <xsl:param name="eventIdStart"/>
    <xsl:param name="symbolPrefix"/>
    <xsl:param name="level"/>
MessageId=<xsl:value-of select="number($eventIdStart)"/>
SymbolicName=<xsl:value-of select="$symbolPrefix"/>_entry
Language=ENGLISH
<xsl:value-of select="$level"/> entry%r
Subsystem: %1%r
Instance: %2%r
Module: %3%r
Component: %4%r
Function: %5%r
Process: %6%r
Thread: %7%r
Identity: %8%r
.

MessageId=<xsl:value-of select="number($eventIdStart)+1"/>
SymbolicName=<xsl:value-of select="$symbolPrefix"/>_exit
Language=ENGLISH
<xsl:value-of select="$level"/> normal exit%r
Subsystem: %1%r
Instance: %2%r
Module: %3%r
Component: %4%r
Function: %5%r
Process: %6%r
Thread: %7%r
Identity: %8%r
.

MessageId=<xsl:value-of select="number($eventIdStart)+2"/>
SymbolicName=<xsl:value-of select="$symbolPrefix"/>_exception
Language=ENGLISH
<xsl:value-of select="$level"/> abnormal exit%r
Subsystem: %1%r
Instance: %2%r
Module: %3%r
Component: %4%r
Function: %5%r
Process: %6%r
Thread: %7%r
Identity: %8%r
Exception ID: %9%r
Exception: %10%r
Exception message: %11%r
Exception properties: %12%r
Trace log: %13%r
Stack: %14%r
.
  </xsl:template>

  <xsl:template name="OtherEventIds">
MessageId=700
SymbolicName=Information
Language=ENGLISH
Detail: %9%r
Subsystem: %1%r
Instance: %2%r
Module: %3%r
Component: %4%r
Function: %5%r
Process: %6%r
Thread: %7%r
Identity: %8%r
.

MessageId=701
SymbolicName=Warning
Language=ENGLISH
Detail: %9%r
Subsystem: %1%r
Instance: %2%r
Module: %3%r
Component: %4%r
Function: %5%r
Process: %6%r
Thread: %7%r
Identity: %8%r
.

MessageId=702
SymbolicName=Exception
Language=ENGLISH
Subsystem: %1%r
Instance: %2%r
Module: %3%r
Component: %4%r
Function: %5%r
Process: %6%r
Thread: %7%r
Identity: %8%r
Exception ID: %9%r
Exception: %10%r
Exception message: %11%r
Exception properties: %12%r
Trace log: %13%r
Stack: %14%r
.

MessageId=703
SymbolicName=Error
Language=ENGLISH
Detail: %9%r
Subsystem: %1%r
Instance: %2%r
Module: %3%r
Component: %4%r
Function: %5%r
Process: %6%r
Thread: %7%r
Identity: %8%r
.    

  </xsl:template>

</xsl:stylesheet>